package com.pesoexpress.service.impl;

import java.io.IOException;

import org.jpos.iso.ISOException;
import org.springframework.stereotype.Service;

import com.pesoexpress.operations.schema.PesoExpressReq;
import com.pesoexpress.operations.schema.PesoExpressResp;
import com.pesoexpress.service.OperationService;
import com.pesoexpress.util.PesoExpressISOUtils;

@Service
public class OperationServiceImpl implements OperationService{

	@Override
	public PesoExpressResp envio(PesoExpressReq request){
		try {
			PesoExpressResp response = PesoExpressISOUtils.sendEnvio(request, "localhost", 10100);
			return response;
		} catch (ISOException e) {
			e.printStackTrace();
			return PesoExpressISOUtils.msgError();
		} catch (IOException e) {
			e.printStackTrace();
			return PesoExpressISOUtils.msgError();
		}
	}
	
	@Override
	public PesoExpressResp retiro(PesoExpressReq request){
		try {
			PesoExpressResp response = PesoExpressISOUtils.sendRetiro(request, "localhost", 10100);
			return response;
		} catch (ISOException e) {
			e.printStackTrace();
			return PesoExpressISOUtils.msgError();
		} catch (IOException e) {
			e.printStackTrace();
			return PesoExpressISOUtils.msgError();
		}
	}
	
	@Override
	public PesoExpressResp reverso(PesoExpressReq request){
		try {
			PesoExpressResp response = PesoExpressISOUtils.sendReverso(request, "localhost", 10100);
			return response;
		} catch (ISOException e) {
			e.printStackTrace();
			return PesoExpressISOUtils.msgError();
		} catch (IOException e) {
			e.printStackTrace();
			return PesoExpressISOUtils.msgError();
		}
	}
	
}
